package com.tozed.android.launcher.simpleui;

import java.util.ArrayList;

import com.tozed.android.launcher.R;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SimpleAddAdapter extends BaseAdapter
{
	public static final int ITEM_ADD_APPS = 8;
	public static final int ITEM_APPLICATION = 2;
	public static final int ITEM_APPWIDGET = 1;
	public static final int ITEM_CHANGE_TO_SIMPLE = 10;
	public static final int ITEM_EDIT_HOME = 9;
	public static final int ITEM_EFFECT = 8;
	public static final int ITEM_MANAGE_APPS = 5;
	public static final int ITEM_MANAGE_SCREENS = 7;
	public static final int ITEM_PEOPLE_SHORTCUT = 7;
	public static final int ITEM_SETTINGS = 6;
	public static final int ITEM_SHORTCUT = 0;
	public static final int ITEM_THEME = 4;
	public static final int ITEM_WALLPAPER = 3;
	private final LayoutInflater mInflater;
	private final ArrayList<ListItem> mItems = new ArrayList();

	public SimpleAddAdapter(SimpleUILauncher simpleUILauncher)
	{
		mInflater = ((LayoutInflater)simpleUILauncher.getSystemService(Context.LAYOUT_INFLATER_SERVICE));
	    Resources res = simpleUILauncher.getResources();
	    
	    // 暂时不需要联系人快捷方式功能
	    //mItems.add(new ListItem(res, R.string.str_add_people_simple, R.drawable.ic_popup_people, ITEM_PEOPLE_SHORTCUT));
	    
	    mItems.add(new ListItem(res, R.string.str_add_applications_simple, R.drawable.ic_popup_app, ITEM_ADD_APPS));
	}
	
	public int getCount()
	{
		return mItems.size();
	}

	public Object getItem(int itemId)
	{
		return mItems.get(itemId);
	}

	public long getItemId(int id)
	{
		return id;
	}

	public View getView(int position, View convertView, ViewGroup parent)
	{
		ListItem listItem = (ListItem)getItem(position);
		if (convertView == null)
			convertView = mInflater.inflate(R.layout.simple_add_list_item, parent, false);
		
		TextView textView = (TextView)convertView;
		textView.setTag(listItem);
		textView.setText(listItem.text);
		
		// large screen set drawable is top?
		//localTextView.setCompoundDrawablesWithIntrinsicBounds(null, listItem.image, null, null);
		textView.setCompoundDrawablesWithIntrinsicBounds(listItem.image, null, null, null);
		return convertView;
	}
	  
	public static class ListItem
	{
		public final int actionTag;
		public final Drawable image;
		public final CharSequence text;

		public ListItem(Resources res, int textResourceId, int imageResourceId, int actionTag)
		{
			text = res.getString(textResourceId);
            if (imageResourceId != -1) {
                image = res.getDrawable(imageResourceId);
            } else {
                image = null;
            }
            this.actionTag = actionTag;
		}

		public ListItem(Resources res, int textResourceId, Drawable imgDrawable, int actionTag)
		{
			text = res.getString(textResourceId);
			if (imgDrawable != null){
				image = imgDrawable;
			}else{
				image = null;
			}
			
			this.actionTag = actionTag;
		}
	}
}
